<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
	<title>首页</title>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
	<meta name="format-detection" content="telephone=no"/> <!--禁止数字串在ok手机中被识别成电话号码-->
	<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
	<!-- ICO -->
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css2/main.css" media="all" />
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css2/style.css" media="all" />
	<!-- iconfont图形样式 -->
	<link rel="stylesheet" href="__PUBLIC__/css2/iconfont/iconfont.css" type="text/css">
</head>
<body>
<div class="main me">

	<div class="me_li me_bank">

		<ul>
			<li>
				<a href="javascript::" id="scanQRCode">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>扫一扫</b></label>
				</a>
			</li>
			<li>
				<a href="javascript::" id="record">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>录音</b></label>
				</a>
			</li>
			<li>
				<a href="javascript::" id="stoprecord">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>停止录音</b></label>
				</a>
			</li>
			<li>
				<a href="javascript::" id="playrecord">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>听录音</b></label>
				</a>
			</li>
			<li>
				<a href="javascript::" id="uploadrecord">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>上传录音</b></label>
				</a>
			</li>
			<li>
				<a href="javascript::" id="downloadrecord">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>下载录音</b></label>
				</a>
			</li>
			<li>
				<a href="javascript::" id="fenx">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>拍照</b></label>
				</a>
			</li>
			<li>
				<a href="javascript::" id="kanz">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>看照片</b></label>
				</a>
			</li>
			<li>
				<a href="javascript::" id="shang">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>上传照片</b></label>
				</a>
			</li>
			<li>
				<a href="javascript::" id="xia">
					<i class="green iconfont">&#xe60a;</i>
					<label><b>下载照片</b></label>
				</a>
			</li>
		</ul>
		<img src="" id="myimg">
		<p style="font-size: 36px; color: #000;">下面是压缩的图片</p>
		<img src="" alt="" title="" id="lrz" style="width: 90%;">
		<canvas></canvas>
		<!-- <canvas style="width: 100%; height: 800px;"></canvas> -->
		<img src="" alt="" title="" id="image" style="width: 80%;">
	</div>
</div>
</body>
<script src="__PUBLIC__/js/jquery-1.10.1.min.js"></script>
<!-- 引入lrz.js -->
<script type="text/javascript" src="__PUBLIC__/mobile/js/lrz.all.bundle.js" charset="UTF-8"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script  type="text/javascript">  

	wx.config({
		debug: true,
		appId:'{$data.appId}',
		timestamp: {$data.timestamp},
		nonceStr: '{$data.nonceStr}',
		signature: '{$data.signature}',
		// jsApiList : [ 'checkJsApi', 'scanQRCode' ]
		jsApiList: [
			'checkJsApi',
			'scanQRCode',
			'startRecord',
			'stopRecord',
			'onVoiceRecordEnd',
			'playVoice',
			'pauseVoice',
			'stopVoice',
			'onVoicePlayEnd',
			'uploadVoice',
			'downloadVoice',
			'getNetworkType',
			'chooseImage',
			'previewImage',
			'uploadImage',
			'onMenuShareAppMessage'
		]  
	});
	wx.error(function(res) {  
		alert("出错了：" + res.errMsg);  
	});  
  
	wx.ready(function() {
		var record = {
			localId: '',
			serverId: '',
			localIds: '',
		};
		wx.checkJsApi({  
			jsApiList : ['uploadImage','previewImage','chooseImage','scanQRCode','startRecord','stopRecord','onVoiceRecordEnd','playVoice','onVoicePlayEnd','onMenuShareAppMessage'],  
			success : function(res) {  
			}  
		});  
  
		//扫描二维码  
		document.querySelector('#scanQRCode').onclick = function() {alert(2)
			wx.scanQRCode({  
				needResult : 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，  
				scanType : [ "qrCode", "barCode" ], // 可以指定扫二维码还是一维码，默认二者都有  
				success : function(res) {
					self.location=res.resultStr;
				}  
			});  
		};//end_document_scanQRCode  

		// 检查网络是WiFi 还是 4g
		wx.getNetworkType({
			success: function (res) {
				var networkType = res.networkType; // 返回网络类型2g，3g，4g，wifi
				jQuery(function() {
					alert(networkType);
				});
			}
		});
		
		// 开始录音
		document.querySelector('#record').onclick = function () {
			alert('luying')
			wx.startRecord();
		};
		
		// 停止录音
		document.querySelector('#stoprecord').onclick = function() {
			alert('停止录音')
			wx.stopRecord({
				success: function (res) {
					record.localId = res.localId;
				}
			});
		};

		// 录音时间超过一分钟没有停止的时候会执行 complete 回调
		wx.onVoiceRecordEnd({
			complete: function (res) {
				record.localId = res.localId;
				// $("#record").html('开始录音');
			}
		});

		//  播放语音
		document.querySelector('#playrecord').onclick = function() {

			if(record.localId == '') {
				alert('你还没录音');
				return;
			}
			//播放录音
			wx.playVoice({
				localId: record.localId
			});
		};

		// 监听语音播放完毕接口
		wx.onVoicePlayEnd({
			success: function (res) {
				record.localId = res.localId; // 返回音频的本地ID
				alert('播放完毕');
			}
		});
		
		//  上传录音
		document.querySelector('#uploadrecord').onclick = function() {
			if(record.localId == '') {
				alert('你还没录音localId');
				return;
			}
			wx.uploadVoice({
				localId: record.localId,
				isShowProgressTips: 1,
				success: function (res) {
					alert(res.serverId)
					record.serverId = res.serverId;
					$.getJSON("{:U('Home/News/sendVoice')}",{user_id:'1', media_id:record.serverId}, function(data) {
						if(data)
							alert("Send successfully");
					});
				}
			});
		};
 
		//  下载录音接口
		document.querySelector('#downloadrecord').onclick = function() {
			if(record.serverId == '') {
				alert('你还没上传录音');
				return;
			}
			wx.downloadVoice({
				serverId: record.serverId, 
				isShowProgressTips: 1,
				success: function (res) {
					record.localId = res.localId;
					alert(record.localId);
				}
			});
		};

		document.querySelector('#fenx').onclick = function() {
			wx.chooseImage({
				count: 1, // 默认9
				sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
				sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
				success: function (res) {
					console.log(res)
					// alert(JSON.stringify(res));
					record.localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
					var $img = $('#lrz');
					// alert(res.localIds);
					$('#myimg').attr('src', res.localIds);
					$img.attr('src', res.localIds[0]);
					// $img.attr('src', 'https://gss0.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/d1a20cf431adcbef0bdbbf8eaeaf2edda2cc9f4f.jpg');
					// $img.attr('src', 'http://www.runoob.com/try/demo_source/img_the_scream.jpg');
					var canvas = $('canvas')[0];
					var context = canvas.getContext("2d");
					$img[0].onload = function() {
						$('canvas').attr({
							width: $img.width() * 2,
							height: $img.height() * 2
						});
					    context.drawImage($img[0], 0, 0, $img.width() * 2, $img.height() * 2);
					    $('#image').attr('src', canvas.toDataURL('image/jpeg', 0.6));
					}
					// lrz(res.localIds[0], {
					// 	width: 500,
					// 	quality: 0.8
					// }).then(function(data) {
					// 	alert(JSON.stringify(data))
					// 	$('#lrz').attr('src', data.base64);
					// });
					wx.uploadImage({
						localId: res.localIds[0], // 需要上传的图片的本地ID，由chooseImage接口获得
						isShowProgressTips: 1, // 默认为1，显示进度提示
						success: function (res) {
							var serverId = res.serverId; // 返回图片的服务器端ID
							$.getJSON("{:U('Home/Face/sendImage')}",{media_id:serverId}, function(data) {
								if(data)
									alert("Send successfully");
							});

						}
					});
					
				}
			});
		};

		document.querySelector('#kanz').onclick = function() {
			wx.previewImage({
				current: 'http://wx.qlogo.cn/mmopen/Iv8D5nD32icIFAmMo47ibhtxEJuYxPSdsGHrrbdPH6DIAQlYXCrHehjP5fDJGPxIrH6ict5XyeCxXIRpiaayMJROQg/0', // 当前显示图片的http链接
				urls: ['http://wx.qlogo.cn/mmopen/Iv8D5nD32icIFAmMo47ibhtxEJuYxPSdsGHrrbdPH6DIAQlYXCrHehjP5fDJGPxIrH6ict5XyeCxXIRpiaayMJROQg/0',] // 需要预览的图片http链接列表
			});
		};

		document.querySelector('#shang').onclick = function() {alert(3)
			if(record.localIds == '') {
				alert('你还没拍照localIds');
				return;
			}
			wx.uploadImage({
				localId: record.localIds, // 需要上传的图片的本地ID，由chooseImage接口获得
				isShowProgressTips: 1, // 默认为1，显示进度提示
				success: function (res) {
					var serverId = res.serverId; // 返回图片的服务器端ID
					alert(serverId);

				}
			});
		};
		  
	});//end_ready  

	  document.querySelector('#uploadrecord1').onclick = function() {
			alert(3)
					$.getJSON("{:U('Home/News/sendVoice')}",{user_id:'1', media_id:2}, function(data) {
						if(data)
							alert("Send successfully");
					});
					// var data = {'user_id':1,'media_id':2};
					// var url = "{:U('Home/News/sendVoice')}";
					// $.post(url, data, function(result){
					//	 console.log("Send successfully");
					// },"JSON");

		};
</script> 
<!-- <script src="http://cdn.ronghub.com/RongIMLib-2.2.5.min.js"></script> -->
<!-- <script src="http://cdn.ronghub.com/RongIMLib-2.0.6.beta.min.js"></script> -->
<script type="text/javascript">

	// RongIMClient.init("tdrvipkstf795");

	// var token = "gPkmL5ttS9lrEgdLgCdZd5puCneoZ5J8SBKB50HnfTeR41a8PDuQj9j87T7Y+jtN+78ZC7pgzEXzZnJ4fYS2oQ==";
	//  // 设置连接监听状态 （ status 标识当前连接状态）
	//  // 连接状态监听器
	//  RongIMClient.setConnectionStatusListener({
	// 	onChanged: function (status) {
	// 		switch (status) {
	// 			//链接成功
	// 			case RongIMLib.ConnectionStatus.CONNECTED:
	// 				alert('链接成功');
	// 				break;
	// 			//正在链接
	// 			case RongIMLib.ConnectionStatus.CONNECTING:
	// 				alert('正在链接');
	// 				break;
	// 			//重新链接
	// 			case RongIMLib.ConnectionStatus.DISCONNECTED:
	// 				alert('断开连接');
	// 				break;
	// 			//其他设备登录
	// 			case RongIMLib.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT:
	// 				alert('其他设备登录');
	// 				break;
	// 			  //网络不可用
	// 			case RongIMLib.ConnectionStatus.NETWORK_UNAVAILABLE:
	// 			  alert('网络不可用');
	// 			  break;
	// 			}
	// 	}});

	//  // 消息监听器
	//  RongIMClient.setOnReceiveMessageListener({
	// 	// 接收到的消息
	// 	onReceived: function (message) {
	// 		// 判断消息类型
	// 		switch(message.messageType){
	// 			case RongIMClient.MessageType.TextMessage:
	// 				   // 发送的消息内容将会被打印
	// 				alert(message.content.content);
	// 				break;
	// 			case RongIMClient.MessageType.VoiceMessage:
	// 				// 对声音进行预加载
	// 				// message.content.content 格式为 AMR 格式的 base64 码
	// 				RongIMLib.RongIMVoice.preLoaded(message.content.content);
	// 				break;
	// 			case RongIMClient.MessageType.ImageMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.DiscussionNotificationMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.LocationMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.RichContentMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.DiscussionNotificationMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.InformationNotificationMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.ContactNotificationMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.ProfileNotificationMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.CommandNotificationMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.CommandMessage:
	// 				// do something...
	// 				break;
	// 			case RongIMClient.MessageType.UnknownMessage:
	// 				// do something...
	// 				break;
	// 			default:
	// 				// 自定义消息
	// 				// do something...
	// 		}
	// 	}
	// });
	// // 连接融云服务器。
	// 	  RongIMClient.connect(token, {
	// 		onSuccess: function(userId) {
	// 		  alert("Login successfully." + userId);
	// 		  yyx();
	// 		},
	// 		onTokenIncorrect: function() {
	// 		  alert('token无效');
	// 		},
	// 		onError:function(errorCode){
	// 			  var info = '';
	// 			  switch (errorCode) {
	// 				case RongIMLib.ErrorCode.TIMEOUT:
	// 				  info = '超时';
	// 				  break;
	// 				case RongIMLib.ErrorCode.UNKNOWN_ERROR:
	// 				  info = '未知错误';
	// 				  break;
	// 				case RongIMLib.ErrorCode.UNACCEPTABLE_PaROTOCOL_VERSION:
	// 				  info = '不可接受的协议版本';
	// 				  break;
	// 				case RongIMLib.ErrorCode.IDENTIFIER_REJECTED:
	// 				  info = 'appkey不正确';
	// 				  break;
	// 				case RongIMLib.ErrorCode.SERVER_UNAVAILABLE:
	// 				  info = '服务器不可用';
	// 				  break;
	// 			  }
	// 			  alert(errorCode);
	// 			}
	// 	  });

	// function yyx(){
	// 		   // 定义消息类型,文字消息使用 RongIMLib.TextMessage
	//  var msg = new RongIMLib.TextMessage({content:"这个就是聊天",extra:"附加信息"});
	//  //或者使用RongIMLib.TextMessage.obtain 方法.具体使用请参见文档
	//  //var msg = RongIMLib.TextMessage.obtain("hello");
	//  var conversationtype = RongIMLib.ConversationType.PRIVATE; // 私聊
	//  var targetId = "1"; // 目标 Id
	//  RongIMClient.getInstance().sendMessage(conversationtype, targetId, msg, {
	// 				// 发送消息成功
	// 				onSuccess: function (message) {
	// 					//message 为发送的消息对象并且包含服务器返回的消息唯一Id和发送消息时间戳
	// 					console.log("Send successfully");
	// 				},
	// 				onError: function (errorCode,message) {
	// 					var info = '';
	// 					switch (errorCode) {
	// 						case RongIMLib.ErrorCode.TIMEOUT:
	// 							info = '超时';
	// 							break;
	// 						case RongIMLib.ErrorCode.UNKNOWN_ERROR:
	// 							info = '未知错误';
	// 							break;
	// 						case RongIMLib.ErrorCode.REJECTED_BY_BLACKLIST:
	// 							info = '在黑名单中，无法向对方发送消息';
	// 							break;
	// 						case RongIMLib.ErrorCode.NOT_IN_DISCUSSION:
	// 							info = '不在讨论组中';
	// 							break;
	// 						case RongIMLib.ErrorCode.NOT_IN_GROUP:
	// 							info = '不在群组中';
	// 							break;
	// 						case RongIMLib.ErrorCode.NOT_IN_CHATROOM:
	// 							info = '不在聊天室中';
	// 							break;
	// 						default :
	// 							info = x;
	// 							break;
	// 					}
	// 					console.log('发送失败:' + info);
	// 				}
	// 			}
	// 		);
	// }
</script>
</html>